#include <iostream>
#include "split.hpp"

char data[34][40] = {
    "$GPZDA,085552.00,13,03,2025,,*6D",
    "$GPZDA,085553.00,13,03,2025,,*6C",
    "$GPZDA,085554.00,13,03,2025,,*6B",
    "$GPZDA,085555.00,13,03,2025,,*6A",
    "$GPZDA,085556.00,13,03,2025,,*69",
    "$GPZDA,085557.00,13,03,2025,,*68",
    "$GPZDA,085558.00,13,03,2025,,*67",
    "$GPZDA,085559.00,13,03,2025,,*66",
    "$GPZDA,085600.00,13,03,2025,,*69",
    "$GPZDA,085601.00,13,03,2025,,*68",
    "$GPZDA,085602.00,13,03,2025,,*6B",
    "$GPZDA,085603.00,13,03,2025,,*6A",
    "$GPZDA,085604.00,13,03,2025,,*6D",
    "$GPZDA,085605.00,13,03,2025,,*6C",
    "$GPZDA,085606.00,13,03,2025,,*6F",
    "$GPZDA,085607.00,13,03,2025,,*6E",
    "$GPZDA,085608.00,13,03,2025,,*61",
    "$GPZDA,085609.00,13,03,2025,,*60",
    "$GPZDA,085610.00,13,03,2025,,*68",
    "$GPZDA,085611.00,13,03,2025,,*69",
    "$GPZDA,085612.00,13,03,2025,,*6A",
    "$GPZDA,085613.00,13,03,2025,,*6B",
    "$GPZDA,085614.00,13,03,2025,,*6C",
    "$GPZDA,085615.00,13,03,2025,,*6D",
    "$GPZDA,085616.00,13,03,2025,,*6E",
    "$GPZDA,085617.00,13,03,2025,,*6F",
    "$GPZDA,085618.00,13,03,2025,,*60",
    "$GPZDA,085619.00,13,03,2025,,*61",
    "$GPZDA,085620.00,13,03,2025,,*6B",
    "$GPZDA,085621.00,13,03,2025,,*6A",
    "$GPZDA,085622.00,13,03,2025,,*69",
    "$GPZDA,085623.00,13,03,2025,,*68",
    "$GPZDA,085624.00,13,03,2025,,*6F",
    "$GPZDA,085625.00,13,03,2025,,*6E",
};

struct ZDA_STRUCT
{
    // 语句头
    char head[7];
    // UTC时
    unsigned char hour;
    // UTC分
    unsigned char minute;
    // UTC秒
    unsigned char second;
    // UTC毫秒
    unsigned char ms;
    // 日
    unsigned char day;
    // 月
    unsigned char month;
    // 年
    unsigned short year;

    unsigned char checksum;
};

struct ZDA_STRUCT parseZDA(char *data)
{
    struct ZDA_STRUCT zda;
    char _data[10][20];
    int count = 0;
    split_string(data, _data, &count);

    memcpy(zda.head, _data[0], 6);
    sscanf(_data[1], "%2hhu%2hhu%2hhu.%2hhu", &zda.hour, &zda.minute, &zda.second, &zda.ms);
    zda.day = atoi(_data[2]);
    zda.month = atoi(_data[3]);
    zda.year = atoi(_data[4]);
    
    zda.checksum = _data[6][0] - 0x30 * 16 + _data[6][1] - 0x30;
    return zda;
}

int main()
{
    struct ZDA_STRUCT zda = parseZDA(data[0]);
    printf("rcv_data:%s,%d:%d:%d.%d,%d-%d-%d,%02X\n", zda.head, zda.hour, zda.minute, zda.second, zda.ms, zda.day, zda.month, zda.year, zda.checksum);

    for(int i = 0; i < 34; i++)
    {
        zda = parseZDA(data[i]);
        printf("rcv_data:%s,%02d:%02d:%02d.%02d,%02d-%02d-%04d,%02X\n", zda.head, zda.hour, zda.minute, zda.second, zda.ms, zda.day, zda.month, zda.year, zda.checksum);
    }
}